home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / editor / amis / viewers / sources / c_viewer.c next >
C/C++ Source or Header  |  1996-12-30  |  5KB  |  210 lines

  1. /*
  2.  
  3.  Viewer       : C.
  4.  Version      : 1.02.
  5.  Date         : 29 December 1996.
  6.  Distribution : freeware.
  7.  Author(s)    : Willem Mestrom & Vincent Groenewold.
  8.  
  9.  Comment      : This is an example of a very simple viewer for AMIS. It
  10.                 shows C code in different colors to improve readability.
  11.  
  12. */
  13.  
  14. #include <exec/types.h>
  15. #include <clib/graphics_protos.h>
  16. #include "viewer.h"
  17.  
  18. void __saveds __asm Display(register __a0 char *text,
  19.                                         register __a1 char *buf,
  20.                                         register __d0 long length,
  21.                                         register __a5 struct EditWin *editwin);
  22. void __saveds SwitchFunc(void);
  23. void MyPrint(struct EditWin *editwin,char *text,long length);
  24.  
  25. void __stdargs _XCEXIT(long);
  26.  
  27. struct List C_keylist = { 0,0,0 };
  28.  
  29. struct GfxBase *GfxBase;
  30. struct AMIS *AMIS;
  31.  
  32. struct Viewer C_Viewer={
  33.     0,0,                                /* must be zero */
  34.     AMIS_0_97,                        /* the version of AMIS which you need at least
  35.                                             to use this viewer */
  36.     0,                                    /* must be zero */
  37.     "C-Source",                        /* name of the viewer */
  38.     0,                                    /* must be zero */
  39.     "(#?.c|#?.h|#?.cpp|#?.cxx|#?.c++)",
  40.                                         /* pattern of files to view with this viewer */
  41.     0,                                    /* no special text at the start of a file */
  42.     0,                                    /* no special text in file to recognize it */
  43.     0,                                    /* no switch function */
  44.     0,0,                                /* flags */
  45.     Display,                            /* the display function */
  46.     0,0,0,0,                            /* standard control functions */
  47.     1,0,0,-1,0,                        /* normal lines */
  48.     0,0,0,0,0,0,                    /* standard control functions */
  49.     &C_keylist,                        /* special keylist */
  50.     0,0,0,                            /* standard control functions */
  51.     "C-Source viewer v1.01||Written by Willem Mestrom & Vincent Groenewold."
  52. };
  53.  
  54. long purple,purple2,leftoffset;
  55.  
  56. struct Viewer __saveds __asm *InitViewer(register __a0 struct AMIS *NewAMIS)
  57. {
  58.     AMIS=NewAMIS;
  59.     C_keylist.lh_Head=(struct Node *)((char *)&C_keylist+4);
  60.     C_keylist.lh_TailPred=(struct Node *)((char *)&C_keylist+4);
  61.     C_Viewer.vw_font=AMIS->AMIS_Normal_Font;
  62.     GfxBase=AMIS->AMIS_GfxBase;
  63.     purple=-1;
  64.     return(&C_Viewer);
  65. }
  66.  
  67. /*        Example of using internal commands inside your own viewer
  68.         To activate this function just add it to the C_Viewer structure.
  69.  
  70. void __saveds SwitchFunc()
  71. {
  72.     AMIS_InternalCommand("Request BODY=\"test\"");
  73. }
  74.  
  75. */
  76.  
  77. void __saveds __asm Display(register __a0 char *text,
  78.                                         register __a1 char *buf,
  79.                                         register __d0 long length,
  80.                                         register __a5 struct EditWin *editwin)
  81. {
  82.     long    bufsign=0,charnum=0,tab,temp3,color;
  83.     char    sign,cppcomment=0;
  84.  
  85.     leftoffset=-(editwin->ed_leftchar);
  86.  
  87.     if(purple==-1)
  88.         purple=ObtainBestPen(AMIS->AMIS_ColorMap,0xaaaaaaaa,0x00000000,0xaaaaaaaa,0);
  89.  
  90.     purple2=ObtainBestPen(AMIS->AMIS_ColorMap,0xaaaaaaaa,0x00000000,0xaaaaaaaa,0);
  91.     if(purple!=purple2)
  92.     {
  93.         ReleasePen(AMIS->AMIS_ColorMap,purple);
  94.         purple=purple2;
  95.     }
  96.     else
  97.     {
  98.         ReleasePen(AMIS->AMIS_ColorMap,purple2);
  99.     }
  100.  
  101.     color=editwin->ed_linesinfo[editwin->ed_line].li_viewerdata;
  102.     if(color!=2)
  103.     {
  104.         if(text[0]=='#')
  105.             color=purple;
  106.         else
  107.             color=1;
  108.     }
  109.  
  110.     SetAPen(editwin->wn_rast,(color==0 ? 3 : color));
  111.     SetBPen(editwin->wn_rast,0);
  112.     tab=(long)editwin->ed_tabsize;
  113.     if(tab==0) tab=8;
  114.     while(charnum<length)
  115.     {
  116.         sign=text[charnum];
  117.         if((sign=='/')&&(text[charnum+1]=='/')&&((color==1)||(color==purple)))
  118.         {
  119.             MyPrint(editwin,buf,bufsign);
  120.             color=2; bufsign=0; cppcomment=1;
  121.             SetAPen(editwin->wn_rast,color);
  122.         }
  123.         if((sign=='*')&&(text[charnum+1]=='/')&&(color==2))
  124.         {
  125.             buf[bufsign]='*'; bufsign++; buf[bufsign]='/'; bufsign++;
  126.             MyPrint(editwin,buf,bufsign);
  127.             color=1; bufsign=0; charnum+=2;
  128.             SetAPen(editwin->wn_rast,color);
  129.         }
  130.         else
  131.         {
  132.             if(((sign=='{')||(sign=='}'))&&(color!=2))
  133.             {
  134.                 MyPrint(editwin,buf,bufsign);
  135.                 color=3; bufsign=0;
  136.                 SetAPen(editwin->wn_rast,color);
  137.                 MyPrint(editwin,&sign,1);
  138.                 color=1; charnum++;
  139.                 SetAPen(editwin->wn_rast,color);
  140.             }
  141.         else
  142.         {
  143.                 if((sign=='/')&&(text[charnum+1]=='*')&&(color!=2))
  144.                 {
  145.                     MyPrint(editwin,buf,bufsign);
  146.                     color=2; bufsign=0;
  147.                     SetAPen(editwin->wn_rast,color);
  148.                 }
  149.             else
  150.             {
  151.                 if((sign=='-')&&(text[charnum+1]=='>')&&(color!=2))
  152.                 {
  153.                     MyPrint(editwin,buf,bufsign); bufsign=0;
  154.                     buf[bufsign]='-'; bufsign++; buf[bufsign]='>'; bufsign++;
  155.                     color=7;
  156.                     SetAPen(editwin->wn_rast,color);
  157.                     MyPrint(editwin,buf,bufsign);
  158.                     bufsign=0; charnum+=2;
  159.                     color=1;
  160.                     SetAPen(editwin->wn_rast,color);
  161.                 }
  162.             else
  163.             {
  164.                 if(sign==9)
  165.                 {
  166.                     temp3=bufsign/tab;
  167.                     temp3++;
  168.                     temp3*=tab;
  169.                     temp3-=bufsign;
  170.                     while(temp3--)
  171.                     {
  172.                         buf[bufsign]=32;
  173.                         bufsign++;
  174.                     }
  175.                     charnum++;
  176.                 }
  177.                 else
  178.                 {
  179.                     buf[bufsign]=sign;
  180.                     bufsign++;
  181.                     charnum++;
  182.                         }
  183.                     }
  184.                 }
  185.             }
  186.         }
  187.     }
  188.  
  189.     MyPrint(editwin,buf,bufsign);
  190.  
  191.     if(cppcomment)
  192.         color=0;
  193.  
  194.     editwin->ed_linesinfo[editwin->ed_line+1].li_viewerdata=color;
  195. }
  196.  
  197. void MyPrint(struct EditWin *editwin,char *text,long length)
  198. {
  199.     leftoffset+=length;
  200.     if(leftoffset>0)
  201.     {
  202.         Text(editwin->wn_rast,text+length-leftoffset,leftoffset);
  203.         leftoffset=0;
  204.     }
  205. }
  206.  
  207. void __stdargs _XCEXIT(long l)
  208. {
  209. }
  210.